package day0224.exer;

public class Demo01 {
    public static void main(String[] args) {
        Shape shape = new Triangle(3, 4, 5);
        shape.calculate();
        shape.show();

        Shape shape1 = new Circle(5);
        shape1.calculate();
        shape1.show();

    }
}

abstract class Shape {

    protected double area;

    private String type;

    public Shape(String type) {
        this.type = type;
    }

    public abstract void calculate();

    public void show() {
        System.out.println( this.type + "的面积为" + this.area );
    };
}


class Triangle extends Shape {

    private double first;

    private double second;

    private double third;

    public Triangle(double first , double second , double third){
        super("三角形");
        this.first = first;
        this.second = second;
        this.third = third;
    }

    @Override
    public void calculate() {
        double p = (first + second + third) / 2;
        this.area = Math.sqrt(p * (p - first) * (p - second) * (p - third));
    }

    @Override
    public void show() {
        System.out.printf("第一条边：%f, 第二条边: %f, 第三条边： %f", first, second, third);
        super.show();
    }
}

class Circle extends Shape {
    private double radius;

    public Circle(double radius) {
        super("圆");
        this.radius = radius;
    }

    @Override
    public void calculate() {
        this.area = Math.PI * Math.pow(radius, 2);
    }

    @Override
    public void show() {
        System.out.println("圆的半径是： " + radius);
        super.show();
    }
}
